package com.yuerlive.rainbow.module.game.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.entity.BankerFlowData;
import com.yuerlive.rainbow.utils.FormatUtil;

import java.util.List;

import butterknife.BindColor;
import butterknife.BindString;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xiaoyi on 2017/7/19.
 */

public class BankerFlowAdapter extends BaseAdapter {

    private List<BankerFlowData.BankerFlowItem> mDatas;
    private Context context;

    public BankerFlowAdapter(List<BankerFlowData.BankerFlowItem> mDatas, Context context) {
        this.mDatas = mDatas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_bankerflow_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == 0){
            holder.imgNew.setVisibility(View.VISIBLE);
        }else {
            holder.imgNew.setVisibility(View.GONE);
        }
        BankerFlowData.BankerFlowItem data = mDatas.get(position);
        holder.tvPos.setText(String.valueOf(position+1));
        holder.tvType.setText(data.getCardType());
        if (data.getBankerFlow()>=0){
            holder.tvCount.setText("+"+ FormatUtil.formatDealTotal(data.getBankerFlow()));
            holder.tvCount.setTextColor(holder.colorRed);
        }else {
            holder.tvCount.setText(""+FormatUtil.formatDealTotal(data.getBankerFlow()));
            holder.tvCount.setTextColor(holder.colorGray);
        }

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tvPos)
        TextView tvPos;
        @BindView(R.id.imgNew)
        ImageView imgNew;
        @BindView(R.id.tvType)
        TextView tvType;
        @BindView(R.id.tvCount)
        TextView tvCount;

        @BindColor(R.color.input_red)
        int colorRed;
        @BindColor(R.color.text_livecard_nick)
        int colorGray;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
